home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / graphics / tierra40.arj / TIERRA / FRONTEND.C < prev    next >
C/C++ Source or Header  |  1992-09-09  |  7KB  |  275 lines

  1. /* frontend.c   9-9-92  Tierra Simulator frontend routines */
  2. /* Tierra Simulator V4.0: Copyright (c) 1991, 1992 Tom Ray & Virtual Life */
  3.  
  4. /* frontend rationale:  to have a common set of functions for passing info
  5.    from Tierra to the front end.  Any particular front end will likely
  6.    use only a subset of all frontend functions.  Those functions that a
  7.    particular front end does not use, will either have to be implemented
  8.    here as dummy functions, or they will have to be ifdef'ed where they
  9.    are called from Tierra */
  10.  
  11. #ifndef lint
  12. static char     sccsid[] = "@(#)frontend.c    1.5 7/21/92";
  13. #endif
  14.  
  15. #include "license.h"
  16. #include "tierra.h"
  17. #include "extern.h"
  18. #ifdef ALCOMM
  19. #include "tmonitor.h"
  20. #include "trequest.h"
  21. #endif
  22.  
  23. /* ======================================================================*/
  24. /* include macros, functions */
  25. /* ======================================================================*/
  26.  
  27. #if FRONTEND == STDIO
  28. #include "tstdio.c"
  29. #endif
  30.  
  31. #if FRONTEND == BASIC
  32. #ifdef __TURBOC__
  33. #include "tturbo.c"
  34.  
  35. #else
  36.  
  37. #include "tcurses.c"
  38. #endif
  39. #endif
  40.  
  41.  
  42.  
  43. #ifdef MEM_CHK
  44. #include <memcheck.h>
  45. #endif
  46.  
  47. /* ======================================================================*/
  48.  
  49. void  FEMessage(n,pbuf)
  50. I32s  n;
  51. I8s  **pbuf;
  52. {   I8s  i;
  53.     I16s msgy;
  54.  
  55. #ifdef MEM_PROF
  56.     if (IMode == PLN_STATS) msgy = MSG_Y + 11; 
  57.     else msgy =  MSG_Y ;
  58. #else 
  59.     if (IMode == PLN_STATS) msgy = MSG_Y + 8; 
  60.     else msgy =  MSG_Y ;
  61. #endif /* else of  MEM_PROF */
  62.  
  63.     for(i = 0; i < n; i++)
  64.     {
  65.        FEPrintf(MSG_X,msgy + i,0,"%s\n", mes[i]);
  66.            if(Log) fprintf(tfp_log,"%s\n", mes[i]);
  67.     }
  68. #if FRONTEND != STDIO
  69.    FEClrmsg(msgy+i); 
  70. if ((IMode == SIZ_HIST) || (IMode == SIZM_HIST) || (IMode == GEN_HIST))
  71.    {
  72.    sleep(2);
  73.    query_species(fe_lines);
  74.    }
  75. #endif
  76.     if(Log) fflush(tfp_log);
  77. }
  78.  
  79. /* ======================================================================*/
  80.  
  81. #ifdef __TURBOC__
  82. void FEError (I32s err_no, I32s err_exit, I32s err_write, ... )
  83. #else /* else of __TURBOC__ */
  84. #ifdef __GNUC__
  85. void FEError (I32s err_no, I32s err_exit, I32s err_write, ... )
  86. #else
  87. void FEError (err_no,err_exit,err_write, va_alist)
  88. I32s err_no,
  89.      err_exit,
  90.      err_write;
  91. va_dcl
  92. #endif /* __GNU__ */
  93. #endif /* else of __TURBOC__ */
  94. {
  95.     va_list ap;
  96.  
  97.     I8s *err_str,
  98.     buf[85],
  99.     ch;
  100.  
  101. #ifdef __TURBOC__
  102.     va_start(ap,err_write);
  103. #else /* else of __TURBOC__ */
  104. #ifdef __GNUC__
  105.     va_start(ap,err_write);
  106. #else
  107.     va_start(ap);
  108. #endif /* __GNUC__ */
  109. #endif /* else of __TURBOC__ */
  110.  
  111.     if ((err_str = va_arg(ap, I8s *)) != NULL)
  112.        {
  113.     vsprintf(buf,err_str,ap);
  114.         FEPrintf(ERR_X,ERR_Y,1,buf);
  115. #if FRONTEND == STDIO
  116.         FEPrintf(ERR_X,ERR_Y,0,"\n");
  117. #endif
  118.        if(Log && (err_no > -200) && (err_no != -110)) 
  119.       {
  120.       vfprintf(tfp_log,err_str,ap);
  121.       fprintf(tfp_log,"\n");
  122.       }
  123.        }
  124.  
  125.     va_end(ap);
  126. #if FRONTEND != STDIO
  127.        if(strlen(buf) > 1 )
  128.       {
  129.           FEPrintf(HLP_X,HLP_Y,1 ,
  130. "                      Tierra ERROR Press any key to continue                ");
  131.           ch = FEGetc(); 
  132. #ifdef __TURBOC__
  133.           if (ch == '~') FEMenu(); /* so that we can examin params */
  134. #endif
  135.       }
  136. #endif
  137.  
  138.     if (err_write == WRITE)
  139.        {IMode = 69;
  140.         sprintf(mes[0],"Writing soup ...");
  141.     FEMessage(1,mes);
  142.        WriteSoup(err_exit);
  143.        IMode = PLN_STATS;
  144.        }
  145.     if (err_exit == EXIT)
  146.        {IMode = 69;
  147.         sprintf(mes[0],"Tierra going down ... "); 
  148.     FEMessage(1,mes);
  149.        if(Log) { fclose(tfp_log);Log=0; }
  150.        while (hangup);
  151.        FEPrintf(HLP_X,HLP_Y,1 ,
  152. "                      Tierra exiting  (PRESS ANY KEY)                   \n"); 
  153.        FEGetc(); 
  154.        FEExit(err_no);
  155.        }
  156.     if(Log) fflush(tfp_log);
  157. }
  158.  
  159. /* ------------------------------------------------------------------------ */
  160.  
  161. #ifdef MEM_PROF
  162.  
  163. void FEMemProf(SizSoup, SizCells, SizFreeMem, SizSl, SizSli,
  164.         SizGl, SizGli, SizGen)
  165. I32s SizSoup, SizCells, SizFreeMem, SizSl, SizSli,
  166.         SizGl, SizGli, SizGen;
  167. {
  168.     if ((IMode == SIZ_HIST) || (IMode == SIZM_HIST) || (IMode == GEN_HIST)) 
  169.         return ;
  170.     FEPrintf(PLN_X,PLN_Y+7,0,
  171.         "    TotMemUse = %6ld  SizFreeMem   = %6ld  SizCells  = %6ld\n",
  172.         TotMemUse, SizFreeMem, SizCells);
  173.     FEPrintf(PLN_X,PLN_Y+8,0,
  174.         "    SizSoup   = %6ld  SizSl        = %6ld  SizSli    = %6ld\n",
  175.         SizSoup, SizSl, SizSli);
  176.     FEPrintf(PLN_X,PLN_Y+9,0,
  177.         "    SizGl     = %6ld  SizGli       = %6ld  SizGen    = %6ld\n",
  178.         SizGl, SizGli, SizGen);
  179. }
  180.  
  181. #endif /* MEM_PROF */
  182.  
  183. /* ------------------------------------------------------------------------ */
  184.  
  185. void  FEPlan(MaxPop, MaxMem, MaxGenPop, MaxGenMem)
  186. I32s  MaxPop, MaxMem;
  187. Genotype  *MaxGenPop, *MaxGenMem;
  188. {   long int  tp;
  189.     tp = time(NULL);
  190.  
  191. #ifdef __TURBOC__
  192.     if (Log) fprintf(tfp_log,"core = %ld\n",(I32u) coreleft());
  193. #endif
  194. #if FRONTEND != STDIO
  195.     if ((IMode == SIZ_HIST) || (IMode == SIZM_HIST)||(IMode == GEN_HIST)) 
  196.        query_species (fe_lines);
  197.     else
  198. #endif
  199.     {
  200.     FEPrintf(PLN_X,PLN_Y,0,
  201.     "InstExeC      = %6ld  Generations  = %6.0f  %s",
  202.         InstExe.m, Generations, ctime(&tp));
  203.     if (GeneBnker)
  204.         {
  205.     FEPrintf(PLN_X,PLN_Y+1,0,
  206.     "    NumCells  = %6ld  NumGenotypes = %6ld  NumSizes  = %6ld\n",
  207.         NumCells, NumGenotypes, NumSizes);
  208.     FEPrintf(PLN_X,PLN_Y+2,0,
  209.     "    AvgSize   = %6ld  NumGenDG     = %6ld  NumGenRQ  = %6ld\n", 
  210.     AverageSize,NumGenDG,NumGenRQ);
  211.         }
  212.     else /* (GeneBnker) */
  213.         {
  214.     FEPrintf(PLN_X,PLN_Y+1,0, "    NumCells  = %6ld\n", NumCells);
  215.     FEPrintf(PLN_X,PLN_Y+2,0, "    AvgSize   = %6ld\n", AverageSize);
  216.         }
  217.     if (InstExe.m)
  218.     {
  219.         FEPrintf(PLN_X,PLN_Y+3,0,
  220.         "    AvgPop    = %6.0f  Births       = %6ld  Deaths    = %6ld\n",
  221.             TimePop,TimeBirth, TimeDeath);
  222.         if (GeneBnker)
  223.       {
  224.          FEPrintf(PLN_X,PLN_Y+5,0,"    MaxGenPop = %6ld  (%4.4ld%3.3s)",
  225.                MaxPop,MaxGenPop->size, MaxGenPop->label);
  226.          FEPrintf(PLN_X+33,PLN_Y+5,0,"    MaxGenMem = %6ld (%4.4ld%3.3s)\n",
  227.                MaxMem / MaxGenMem->size, MaxGenMem->size, MaxGenMem->label);
  228.           }
  229.         }
  230.     FEPrintf(PLN_X,PLN_Y+((InstExe.m)?4:3),0,
  231.     "    RateMut   = %6ld  RateMovMut   = %6ld  RateFlaw  = %6ld\n",
  232.         RateMut, RateMovMut, RateFlaw);
  233.    } /* end of else on IMode */
  234. if (Log)
  235.     {
  236.     fprintf(tfp_log,"\nie%ld gn%.0f %s",
  237.         InstExe.m, Generations, ctime(&tp));
  238.     fprintf(tfp_log, "nc%ld ng%ld ns%ld\n",
  239.         NumCells, NumGenotypes, NumSizes);
  240.     fprintf(tfp_log,"as%ld rq%ld dg%ld\n",
  241.         AverageSize, NumGenRQ, NumGenDG);
  242.     if (InstExe.m)
  243.         {
  244.         fprintf(tfp_log,"bi%ld de%ld ap%.0f\n",
  245.             TimeBirth, TimeDeath,TimePop);
  246.         if (GeneBnker)
  247.           {
  248.            fprintf(tfp_log,"mp%ld @ %4.4ld%3.3s",
  249.                MaxPop,MaxGenPop->size, MaxGenPop->label);
  250.            fprintf(tfp_log," mg%ld @ %4.4ld%3.3s\n",
  251.                MaxMem / MaxGenMem->size, MaxGenMem->size, MaxGenMem->label);
  252.           }
  253.         }
  254.     fprintf(tfp_log,
  255.         "rm%ld mm%ld rf%ld\n",
  256.         RateMut, RateMovMut, RateFlaw);
  257.        fprintf(tfp_log,"\n");
  258.     fflush(tfp_log);
  259.     }
  260. #ifdef ALCOMM
  261.          if ( MIsDFEnabled( TrtPlanEvent ) )
  262.               {
  263.               TPlan();
  264.               }
  265. #endif /* ALCOMM */
  266.  
  267. }
  268.  
  269.  
  270.  
  271. /* ======================================================================*/
  272. /* ======================================================================*/
  273. /* ======================================================================*/
  274.  
  275.